package cn.edu.sjtu.se.dslab.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import cn.edu.sjtu.se.dslab.dao.IBaseDao;
import cn.edu.sjtu.se.dslab.dao.IEntityZoneDao;
import cn.edu.sjtu.se.dslab.project.EntityZone;

@Repository("entityZoneDao")
public class EntityZoneDaoImpl implements IEntityZoneDao{

		@Resource(name = "baseDao")
		private IBaseDao<EntityZone> baseDao;
		
		@Override
		public EntityZone queryById(long id) {
			return baseDao.queryById(EntityZone.class, id);
		}

		@Override
		public EntityZone queryByName(String name) {
			StringBuffer hql = new StringBuffer();
			hql.append("from EntityZone where name=");
			hql.append("'" + name + "'");
			return baseDao.queryObject(hql.toString());
		}

		@Override
		public List<EntityZone> queryByList() {
			return baseDao.queryList(EntityZone.class.getName());
		}

		@Override
		public void save(EntityZone entityZone) {
			baseDao.save(entityZone);
		}

		@Override
		public EntityZone update(EntityZone entityZone) {
			return baseDao.update(entityZone);
		}

		@Override
		public List<EntityZone> queryByProject(long projectId) {
			StringBuilder sql = new StringBuilder();
			sql.append("from EntityZone where project_id='");
			sql.append(projectId).append("'");
			return baseDao.query(sql.toString());
		}
		
		@Override
		public EntityZone queryByProjectAndName(long projectId, String name){
			StringBuilder sql = new StringBuilder();
			sql.append("from EntityZone where project_id='");
			sql.append(projectId).append("' and name = '").append(name).append("'");
			return baseDao.queryObject(sql.toString());
		}

		@Override
		public void delete(EntityZone entityZone) {
			baseDao.delete(entityZone);
		}
		
		@Override
		public List<EntityZone> queryByCategory(long categoryId) {
			StringBuilder sql = new StringBuilder();
			sql.append("from EntityZone where entity_zone_category_id='");
			sql.append(categoryId).append("'");
			return baseDao.query(sql.toString());
		}

}
